home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-04-08 | 8.8 KB | 216 lines | [TEXT/CCL2] |
- #|
- utilities.lisp
-
- Defines some utilities needed by the Mini-Application
- sample program.
-
- For further info, see files "About Mini-App" and "Instructions".
-
-
- Copyright 1990, 1991 by Ruben Kleiman for Apple Computer, Inc.
- Acknowledgement: drag-inverted-region modified from a version by Dave Vronay.
-
- Change History.
- 03-12-92 slm Updated file header comments.
- 01-19-92 slm get-resource-handle:
- added #_GetIcon for B&W systems after creating B&W ICONs.
- numberp -> integerp.
- ostype supersedes restype-from-string.
- restype-from-string: superseded so removed.
- 01-18-92 slm macro get-wmgr-port has been updated:
- %stack-block -> rlet
- _GetWMgrPort -> require-trap #_GetWMgrPort
- 01-18-92 slm function desktop-rect has been updated:
- get-record-field -> pref
- #x9EE (=#$GrayRgn) -> #_GetGrayRgn
- 01-17-92 slm ccl::class-precedence-list -> class-precedence-list
- now exported and documented.
- ccl::with-clip-rect -> with-clip-rect
- now exported but may not be documented.
- (ccl::mode-arg :patxor) -> (position :PatXOr *pen-modes*)
- Similarly for :patCopy.
- 01-17-92 slm _openresfile -> #_OpenResFile (2x)
- _curresfile -> #_CurResFile
- _useresfile -> #_UseResFile (2x)
- _GetCicon -> #_GetCIcon
- _getnamedresource -> #_GetNamedResource
- _getresource -> #_GetResource
- _GetPenState -> #_GetPenState
- _PenMode -> #_PenMode (3x)
- _pt2rect -> #_Pt2Rect (2x)
- _FrameRect -> #_FrameRect (4x)
- _SetPenState -> #_SetPenState
- _CopyRgn -> #_CopyRgn (4x)
- _InverRgn -> #_InvertRgn (3x) ("t" added)
- _getmouse -> #_GetMouse
- _offsetRgn -> #_OffsetRgn
- _XORRgn -> #_XOrRgn
- In addition, most keywords such as :errchk were removed.
-
- |#
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;
- ;;; get-wmgr-port
- ;;;
- ;;; Gets the window manager's port
- ;;;
- (defmacro get-wmgr-port ()
- `(rlet ((port :pointer))
- (require-trap #_GetWMgrPort port)
- (%get-ptr port)))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; open-resource-file
- ;;;
- ;;; Given a filename, opens its resource fork.
- ;;; Returns the file reference number.
- ;;;
- (defun open-resource-file (filename)
- (let ((tempfile (with-pstrs ((tempfile (namestring (truename filename))))
- (#_OpenResFile tempfile))))
- (if (/= tempfile -1)
- tempfile)))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; get-resource-handle
- ;;;
- ;;; Given the resource type and either its name or id, returns its handle.
- ;;; If a resource-file is provided, then that one will be used.
- ;;;
- (defun get-resource-handle (type name-or-id &optional resource-file
- &aux old-resource-file res)
- (setq old-resource-file (#_CurResFile))
- (unwind-protect
- (progn
- (unless (and (stringp type) (= (length type) 4))
- (error "TYPE SHOULD BE A STRING OF LENGTH 4."))
- (when (and resource-file
- (probe-file resource-file)
- (setq resource-file (namestring (truename resource-file))))
- (with-pstrs ((fn resource-file))
- (setq resource-file (#_OpenResFile fn)))
- (#_UseResFile resource-file))
- (case (read-from-string type)
- (cicn (setq res (#_GetCIcon name-or-id))) ;name-or-id must be ID
- (ICON (setq res (#_GetIcon name-or-id))) ;name-or-id must be ID
- (OTHERWISE
- (cond ((stringp name-or-id)
- (with-pstrs ((name name-or-id))
- (setq res (#_GetNamedResource type name))))
- ((integerp name-or-id)
- (setq res (#_GetResource type name-or-id)))
- (t
- (error "A RESOURCE NAME OR ID SHOULD HAVE BEEN PROVIDED."))))))
- (#_UseResFile old-resource-file)
- res))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; subclass-of
- ;;;
- ;;; Is class A a subclass of B?
- ;;;
- (defun subclass-of (A B)
- (and (symbolp A)
- (symbolp B)
- (memq (find-class A)
- (class-precedence-list (find-class B)))
- T))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; select-rectangle [window]
- ;;;
- ;;; This allows the user to drag a gray rectangle on a window
- ;;; Returns the topleft and bottomright of the selected rectangle.
- ;;;
- (defmethod select-rectangle ((window window))
- (let* ((anchor-point (view-mouse-position window))
- (old-mouse anchor-point)
- (new-mouse old-mouse)
- (port (wptr window)))
- (rlet ((r :rect)
- (old-pen-state :penstate))
- (with-port port
- (#_GetPenState old-pen-state)
- (#_PenMode (position :PatXOr *pen-modes*))
- ; (rset port window.pnPat *gray-pattern*)
- (#_Pt2Rect :long anchor-point :long new-mouse :ptr r)
- (#_FrameRect r)
- (loop
- (unless (mouse-down-p) (return)) ;return when the mouse lets up
- (unless (eq old-mouse new-mouse)
- (#_FrameRect r)
- (#_Pt2Rect :long anchor-point :long new-mouse :ptr r)
- (#_FrameRect r)
- (sleep 1/60)
- (setq old-mouse new-mouse))
- (setq new-mouse (view-mouse-position window)))
- (#_FrameRect r)
- (#_SetPenState old-pen-state)
- (values (rref r rect.topleft)
- (rref r rect.bottomright))))))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; desktop-rect
- ;;;
- ;;; Returns the desktop rectangle.
- ;;; Obviously not something whose value you should alter.
- ;;;
- (defun desktop-rect ()
- (pref (#_GetGrayRgn) :region.rgnbbox))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; drag-inverted-region
- ;;;
- ;;; Will produce an inverted region which may be dragged with the mouse.
- ;;; Returns the offset of the drag from the starting position.
- ;;;
- (defmethod drag-inverted-region ((window window) region &key (start 0))
- (let* ((wOffset (view-position window)) ; Screen coordinates of window
- (where (add-points start wOffset)) ; Screen coordinates of start position
- (op where)
- (mouse-rect (make-record :rect)) ; Rectangle for mouse position
- (nregion (new-region))
- (oregion (new-region))
- (sregion (new-region))
- (wideOpen (make-record :rect)) ; Clip to rectangle (will be desktop)
- (old-point where)
- (dragCenter 0) ; needs to be set to something ***
- shift)
- ;; Use desktop rectangle as the one to clip to:
- (copy-record (desktop-rect) :rect wideOpen)
- (unwind-protect
- (progn
- (offset-region region wOffset)
- (with-port (get-wmgr-port)
- (with-clip-rect wideOpen
- (#_PenMode (position :PatXOr *pen-modes*))
- (#_CopyRgn :ptr region :ptr nregion)
- (#_CopyRgn :ptr nregion :ptr oregion)
- (#_InvertRgn :ptr oregion)
- (do ((where where (progn (#_GetMouse :ptr mouse-rect)
- (%get-long mouse-rect))))
- ((not (mouse-down-p)) ; Has mouse been released?
- (setq old-point where)) ; Yes: return where we are and quit DO
- (cond ((eq old-point where)) ; Do nothing if mouse has not moved
- (T ; Mouse has moved!
- (#_CopyRgn :ptr oregion :ptr nregion)
- (setq shift (subtract-points where old-point)) ;; figure how far we moved
- (#_OffsetRgn :ptr region :long shift) ;; offset the region
- (setq dragCenter (add-points shift dragCenter))
- (#_CopyRgn :ptr region :ptr oregion)
- (#_XOrRgn :ptr oregion :ptr nregion :ptr nregion)
- (#_InvertRgn :ptr nregion)
- (setq old-point where))))
- (#_PenMode (position :patCopy *pen-modes*))
- (#_InvertRgn :ptr oregion))))
- (dispose-record mouse-rect :rect)
- (dispose-record wideOpen :rect)
- (dispose-region nregion)
- (dispose-region oregion)
- (dispose-region sregion))
- (subtract-points old-point op)))
-
- ;end of file utilities.lisp
- ;------------------------------------------------
-